package com.sms.core.request;

import java.util.HashMap;
import java.util.Map;

import com.sms.core.utils.TemplateUtils;
import com.sms.domain.entity.Application;
import com.sms.domain.entity.ChannelConfig;
import com.sms.domain.entity.Template;

/**
 * @desc 通道短信发送上下文
 * @author wjw
 * @time 2017年11月16日下午3:30:51
 */
public class SendContext {
    
    /** 应用 */
    private Application application;
    /** 接收手机号 */
    private String mobile;
    /** 发送内容 */
    private String content;
    /** 发送人 */
    private String fromUser;
    /** 接收人 */
    private String toUser;
    /** 短信模板 */
    private Template template;
    /** 短信模板参数变量 */
    private Map<String, String> parameters;
    /** 通道配置 */
    private ChannelConfig channelConfig;
    
    /**
     * 构造函数
     */
    public SendContext() {
        super();
    }
    
    /**
     * 构造函数
     * @param ssr
     */
    public SendContext(SmsRequest ssr) {
    	this.setMobile(ssr.getMobile());
        this.setContent(ssr.getContent());
        this.setFromUser(ssr.getFromUser());
        this.setToUser(ssr.getToUser());
        this.setParameters(new HashMap<>(ssr.getParameters()));
    }
    
    /**
     * 是否是模板短信
     * @return xx
     */
    public boolean isTemplate() {
        return template != null;
    }
    
    /**
     * 将模板转换为内容
     * @return xx
     */
    public String getSendContent() {
        if (isTemplate()) {
            return TemplateUtils.builderTemplate(getTemplateContent(), parameters);
        }
        return this.content;
    }
    
    public String getMobile() {
        return mobile;
    }
    public void setMobile(String mobile) {
        this.mobile = mobile;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    public String getFromUser() {
        return fromUser;
    }
    public void setFromUser(String fromUser) {
        this.fromUser = fromUser;
    }
    public String getToUser() {
        return toUser;
    }
    public void setToUser(String toUser) {
        this.toUser = toUser;
    }
    public Map<String, String> getParameters() {
        return parameters;
    }
    public void setParameters(Map<String, String> parameters) {
        this.parameters = parameters;
    }
    public String getTemplateContent() {
        return template.getContent();
    }
    public ChannelConfig getChannelConfig() {
        return channelConfig;
    }
    public void setChannelConfig(ChannelConfig channelConfig) {
        this.channelConfig = channelConfig;
    }
    public Application getApplication() {
        return application;
    }
    public void setApplication(Application application) {
        this.application = application;
    }
    public Template getTemplate() {
        return template;
    }
    public void setTemplate(Template template) {
        this.template = template;
    }
    
    @Override
    public String toString() {
        return "SendSmsContext [application=" + application + ", mobile=" + mobile + ", content=" + content + ", fromUser=" + fromUser + ", toUser="
            + toUser + ", template=" + template + ", parameters=" + parameters + ", channelConfig=" + channelConfig + "]";
    }
    
}
